#include<iostream>
#include<vector>
#include <cstdint>

int main() {
    std::vector<uint8_t> data = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0};
    uint16_t var;

    if (data.size() >= 2) {
        // 方法1
        var = (static_cast<uint16_t>(data[data.size() - 2])) |
              static_cast<uint16_t>(data[data.size() - 1]) << 8;    // 小端
        std::cout << "The last two bytes are: "<< std::hex<< var<< std::endl;
        // 方法2
        var = *(uint16_t *)((data.data()+(data.size()-2)));
        std::cout << "22 The last two bytes are: "<< std::hex<< var<< std::endl;

    } else {
        std::cout << "The data vector has less than 2 bytes."<< std::endl;
    }

    return 0;
}
